package com.hssy.wululuaplan.controller;


import com.hssy.wululuaplan.common.Result;
import com.hssy.wululuaplan.form.AttendanceForm;
import com.hssy.wululuaplan.service.AttendanceService;
import com.hssy.wululuaplan.vo.AttendanceCaseVo;
import com.hssy.wululuaplan.vo.AttendanceCaseVo2;
import com.hssy.wululuaplan.vo.ClassRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 考勤表 前端控制器
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-28
 */
@Api(tags = "签到管理")
@RestController
@RequestMapping("/wululuaplan/attendance")
public class AttendanceController {

    @Resource
    private AttendanceService attendanceService;

    @ApiOperation(value = "查询指定课程计划的签到情况")
    @GetMapping("/findAttendanceByScheduleId")
    public Result<AttendanceCaseVo> findAttendanceByScheduleId(@RequestParam(value = "scheduleId")Integer scheduleId) {
        AttendanceCaseVo vo = attendanceService.findAttendanceByScheduleId(scheduleId);
        return Result.success(vo);
    }

    @ApiOperation(value = "查询指定课程计划的签到情况V2")
    @GetMapping("/v2/findAttendanceByScheduleId")
    public Result<List<AttendanceCaseVo2>> findAttendanceByScheduleIdV2(@RequestParam(value = "scheduleId")Integer scheduleId) {
        List<AttendanceCaseVo2> list = attendanceService.findAttendanceByScheduleIdV2(scheduleId);
        return Result.success(list);
    }

    @ApiOperation(value = "签到")
    @GetMapping("/attendance")
    public Result<AttendanceCaseVo> attendance(@RequestParam(value = "scheduleId")Integer scheduleId,
                                               @RequestParam(value = "studentId")Integer studentId) {
        Integer result = attendanceService.attendance(scheduleId, studentId);
        return Result.success();
    }

    @ApiOperation(value = "批量签到")
    @PostMapping("/batchAttendance")
    public Result<String> batchAttendance(@RequestBody AttendanceForm form) {
        attendanceService.batchAttendance(form.getScheduleId(), form.getStudentIds());
        return Result.success();
    }

    @ApiOperation(value = "查询指定学生的签到情况", notes = "即查看指定学生的上课记录")
    @GetMapping("/findSignInRecordListByStudentId")
    public Result<List<ClassRecordVo>> findSignInRecordListByStudentId (@RequestParam(value = "studentId")Integer studentId) {
        List<ClassRecordVo> list = attendanceService.findSignInRecordListByStudentId(studentId);
        return Result.success(list);
    }

    @ApiOperation(value = "查询当前计划的签到状态")
    @GetMapping("/status")
    public Result<Integer> getStatus (@RequestParam(value = "scheduleId")Integer scheduleId) {
        Integer status = attendanceService.getStatus(scheduleId);
        return Result.success(status);
    }

    @ApiOperation(value = "查询是否存在未签到的计划")
    @GetMapping("/findNoFinish")
    public Result<Long> findNoFinish() {
        Long num = attendanceService.findNoFinish();
        return Result.success(num);
    }
}

